package GUI;

import processing.core.PImage;


class CatchPhraseInfoPanelButton extends Component
{
    public boolean pressed;
	public boolean selected =false;
	public Control.CatchPhrase catchPhrase;
	////////////////////////////////////////////////////////////////////////////////////////////////////
	public CatchPhraseInfoPanelButton()
	{
		width = 200;
		height = 25;
	}
	public void setLabel(String name)
	{
		label = name;

	}
	public void draw()
	{
		Utils.globalProcessing.textFont(Utils.plotFont, 19);
		if(label.length()>Utils.MAX_CATCHPHRASE_LENGTH-5)
			width = 185;
		else width = (int)(Utils.globalProcessing.textWidth(label)) ;

		int cx = x;
		int cy = y;

		if(label != null)
		{
			Utils.globalProcessing.textAlign(Utils.globalProcessing.LEFT);

			if(mouseOver()) 
			{
				super.draw();
				if(Utils.globalProcessing.mousePressed)
				{

					Utils.gu.drawVGradient(x, y + height, width, -height, Utils.globalProcessing.color(150, 150, 180), 80, Utils.globalProcessing.color(150, 150, 180), 255, (float)0.8);    
					Utils.gu.drawBox(x, y, width, height, 0, Utils.globalProcessing.color(150, 150, 200), 255);
					Utils.gu.drawBox(x, y, width, height, 1, Utils.globalProcessing.color(150, 150, 200), 150);
	                pressed = true;
					cx += 2;
					cy += 2;
				}
				else if(pressed)
	            {
	                pressed = false;
	                if(selected){
	                	selected = false;
	                	Utils.catchPhrasesSelected.remove(catchPhrase);
	                	//System.out.println(Utils.catchPhrasesSelected);
	            		Utils.graphArea.createLineGraphPoints();
	                }
	                else {
	                	Utils.ccip.removeOtherCatchPhrases(this);
	                	selected = true;
	                	if(!Utils.catchPhrasesSelected.contains(catchPhrase)){
		                	Utils.catchPhrasesSelected.add(catchPhrase);
		            		Utils.graphArea.createLineGraphPoints();
		            		
	                	}
	                	else System.out.println("Error catch Phrase insert already present");	                	

	                }
	                
	            }
				
				
				
				//if the label is too long draw an info box containing the full string
				if(label.length()>Utils.MAX_CATCHPHRASE_LENGTH)
					Utils.catchPhraseInfoPanelHighLight = this;

				
			}
			else
	        {
	            pressed = false;
	            if(Utils.catchPhraseInfoPanelHighLight == this)
					Utils.catchPhraseInfoPanelHighLight = null;
	        }

			Utils.globalProcessing.strokeWeight(1);
			Utils.globalProcessing.fill(255);
			if(selected)
				Utils.globalProcessing.textFont(Utils.plotBoldFont, 13);
			else
				Utils.globalProcessing.textFont(Utils.plotFont, 13);
			if(label.length()>Utils.MAX_CATCHPHRASE_LENGTH)
				Utils.globalProcessing.text(label.substring(0, Utils.MAX_CATCHPHRASE_LENGTH)+"...", cx + 5, cy + 15);
			else
				Utils.globalProcessing.text(label, cx + 5, cy + 15);


		}
	}
	
	public void drawInfoBox(int x,int y,int width, String label){
	    Utils.globalProcessing.fill(200);
	    Utils.globalProcessing.stroke(80);
	    Utils.globalProcessing.strokeWeight(1);
	    Utils.globalProcessing.rect(x, y, width, 30);

	    Utils.globalProcessing.fill(0);
	    //Utils.globalProcessing.textFont(Utils.globalProcessing.plotFont, 14);
	    Utils.globalProcessing.textAlign(Utils.globalProcessing.LEFT);
	    Utils.globalProcessing.text(label, x + 5, y + 20);
	}
	

	////////////////////////////////////////////////////////////////////////////////////////////////////
	PImage icon;
	String label;
}